package com.john.cloud.feigin.main;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @Author: JohnCoding
 * @Description:
 * @date: 2020/4/28 13:50
 */
public class Main extends BaseMain implements Cloneable{
    static {
        System.out.println("子类静态代码块");
    }

    {
        System.out.println("子类代码块1");
    }

    {
        System.out.println("子类代码块2");
    }

    public Main() {
        System.out.println("子类构造");
    }

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, CloneNotSupportedException, IOException {
        System.out.println("-------使用new关键字-------");
        Main main = new Main();
        System.out.println("------Class.forName------");
        Class<?> name = Class.forName("com.example.demo.main.Main");
        Main newInstance = (Main) name.newInstance();
        System.out.println("------ClassLoader------");
        Class<?> aClass = ClassLoader.getSystemClassLoader().loadClass("com.example.demo.main.Main");
        Main main1 = (Main) aClass.newInstance();
        System.out.println("------clone-----");
        Main main2 = (Main) main1.clone();
        System.out.println("-----反序列化------");
        ObjectInputStream in = new ObjectInputStream(new FileInputStream("data.obj"));
        Main main3 = (Main) in.readObject();
    }


    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
